home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 293_01 / deppp.c < prev    next >
C/C++ Source or Header  |  1989-08-23  |  2KB  |  77 lines

  1. /************************ Distances.c ****************************
  2.  
  3.               Distances.C
  4.     Example 3-D surface reconstruction distance shading program
  5.  
  6. Daniel Geist
  7. Michael W. Vannier
  8.  
  9. Mallinckrodt Institute of Radiology
  10. Washington University School of Medicine
  11. 510 S. Kingshighway Blvd.
  12. St. Louis, Mo. 63110
  13.  
  14. *******************************************************************/
  15.  
  16. #include <stdio.h>
  17.  
  18. #define LINE_SIZE 256
  19. #define HEADER_SIZE 512
  20. #define CTLINE_SIZE 512
  21.  
  22. int FIRSTSLICE,LASTSLICE,THRESHOLD; /* some global variables */
  23. int  buffer[LINE_SIZE];
  24. char ybuf[LINE_SIZE];
  25.  
  26. /* input and output files */
  27. char *fnamein="ctbild.000",*fnd="dis.out";
  28.  
  29. /* Set input file name - add number to file extension name*/
  30. setfilename(filenum)
  31. int filenum;
  32. {
  33.     fnamein[7]=filenum/100+'0';
  34.     fnamein[8]=(filenum%100)/10+'0';
  35.     fnamein[9]='0'+filenum%10;
  36. }
  37. create_distance_shades()
  38. {
  39.     int z,x,y;
  40.     FILE *fd,*fn;
  41.     fd=fopen(fnd,"wb");                  /*open output file */
  42.     for(z=0;z<(LASTSLICE-FIRSTSLICE+1);z++){  /* for each slice*/
  43.         setfilename(FIRSTSLICE+z);       /*open slice file */
  44.         fn=fopen(fnamein,"rb");
  45.         fseek(fn,(long)HEADER_SIZE,SEEK_SET);    /* read header    */
  46.         for(y=0;y<LINE_SIZE;y++){           /*for each line */
  47.             fread(buffer,1,CTLINE_SIZE,fn);   /*read line */
  48.             /* find Threshold transition */
  49.             for(x=1;(x<LINE_SIZE) && (buffer[x]<THRESHOLD);x++);
  50.             if(x<LINE_SIZE) ybuf[y]=LINE_SIZE-x;  /* if transition then distance shade */
  51.             else ybuf[y]=0;           /*else empty */
  52.         }
  53.         fclose(fn);              /*close scan file */
  54.         fwrite(ybuf,1,LINE_SIZE,fd);
  55.         printf("did %d \n",z);
  56.     }
  57.     fclose(fd);                /* close output file */
  58. }
  59.  
  60.  
  61. /**********************************************************/
  62. /**** MAIN ***** MAIN ***** MAIN ***** MAIN ***** MAIN ****/
  63. /**********************************************************/
  64. main()
  65. {
  66.     /* first get some parameters from user */
  67.     printf("Enter Starting scan number: ");
  68.     scanf("%d",&FIRSTSLICE);
  69.     printf("Enter ending scan number: ");
  70.     scanf("%d",&LASTSLICE);
  71.     printf("Enter threshold number: ");
  72.     scanf("%d",&THRESHOLD);
  73.     THRESHOLD+=1024;
  74.  
  75.     create_distance_shades();
  76. }
  77.